
clear all
set more off

cap program drop exp_wooldridge_gmm
program define exp_wooldridge_gmm
	*! Poisson dynamic panel exponential feedback model
	syntax varlist if, at(name) lhs(varname)

	tempvar lambda

	matrix score double `lambda' = `at' `if', eq(#1)
	replace `lambda' = exp(`lambda')
	replace `varlist' = (`lhs' / `lambda') - (L.`lhs' / L.`lambda') `if'
end

include "bill-analysis/bill_setup.do"

loc controls "`gov' `politics' i.year"

// make sure we only use data 1990-2014 for all models, otherwise the GMM
// model runs into issues (it tries to use pre-1990 lags when non-missing)
keep `rng'

eststo clear

xtpoisson `billdv' L.`shoot' `controls' `rng', `opt'
eststo m1

// GMM estimation of the exponential feedback model
gmm exp_wooldridge_gmm `rng', lhs(`billdv') nequations(1) vce(cluster fips) /*
    */ onestep parameters({`billdv': L.`shoot' L.`billdv' `controls'}) /*
    */ instruments(L.(L.`shoot' L.`billdv' `politics' `gov') i.year, noconstant)
eststo m2

poisson `billdv' L.`shoot' L.`billdv' `controls' i.fips `rng', vce(cluster fips)
eststo m3

poisson `billdv' L.`shoot' L(1/3).`billdv' `controls' i.fips `rng', vce(cluster fips)
eststo m5

poisson `billdv' L.`shoot' L(1/3).`billdv' `controls' `rng', vce(cluster fips)
eststo m6

poisson `billdv' L.`shoot'  `controls' `rng', vce(cluster fips)
eststo m7

esttab, noomit nobase drop(*.year *.fips) order(L.`shoot' L*.`billdv') /*
	*/ b(3) se(3) starlevels(* .10 ** .05 *** .01)

writemodel using "`out'/time_series", ext(csv) drop(*.year *.fips) order(L.`shoot' L*.`billdv')

exit
